<?php
class post_model extends my_model{

	function __construct(){
		parent::__construct();
		$this->_prefix = "pos";
		$this->_column = array(
								'id'						=> $this->_prefix."_id",
								'title'					=> $this->_prefix."_title",
								'content'				=> $this->_prefix."_content",
								'usr_ip'				=> $this->_prefix."_usr_ip",
								'status'				=> $this->_prefix."_status",
								'comment_status'=> $this->_prefix."_comment_status",
								'usr_id'				=> $this->_prefix."_usr_id",
								'cat_id'				=> $this->_prefix."_cat_id",
								'typ_id'				=> $this->_prefix."_typ_id",
								'cr_date'				=> $this->_prefix."_cr_date",
								'lu_date'				=> $this->_prefix."_lu_date",
								'lu_uid'				=> $this->_prefix."_lu_uid",
								'update_date'		=> $this->_prefix."_update_date",
								'url'						=> $this->_prefix."_url",
								'type'					=> $this->_prefix."_type",
								'code'					=> $this->_prefix."_code",
								'is_dummy'			=> $this->_prefix."_is_dummy",
								'dummy_data'		=> $this->_prefix."_dummy_data",
								'view'					=> $this->_prefix."_view"
		);
	}

	function get($options = NULL){
    $this->db->where("pos_type","post");
    $posts = parent::get($options);
    if(!empty($posts)){
    	$this->load->model("images_model","imagesModel");
			foreach ($posts as $key => $value) {
				$posts[$key]["images"] = $this->imagesModel->get(array("where"=>array("pos_id"=>$value["id"])));
				$posts[$key]["categories"] = array_reverse(Util::getCategoryInherit($value["cat_id"]));
				$posts[$key]["meta"] = Util::getPostMeta($posts[$key]["id"]);
				$posts[$key]["type"] = Util::getType($posts[$key]["typ_id"]);
				$posts[$key]["comment_count"] = Util::getCommentCount($posts[$key]["id"]);
				$posts[$key]["user"] = $this->ion_auth->user_array($posts[$key]["usr_id"]);
			}
		}
    return $posts;
  }

	function getPostByGroup($options = NULL){
    //$this->db->join("ci_group","ci_group.grp_id = ci_user.usr_group");
    $posts = self::get($options);
    return $posts;
	}

	function add($options = NULL){
		$this->db->set("pos_type","post");
		return parent::add($options);
	}

}
?>